package com.zzx.controller;

import com.zzx.entity.ApiResult;
import com.zzx.entity.TProduct;
import com.zzx.service.TProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "产品 模块")
@RestController
@RequestMapping("/TProduct")
public class TProductController {

    @Resource
    private TProductService tProductService;

    @ApiOperation(value = "新增、编辑")
    @PostMapping("/add")
    public ApiResult add(@RequestBody TProduct param) {
        tProductService.add(param);
        return ApiResult.ok();
    }

    @ApiOperation(value = "列表查询")
    @PostMapping("/selectBy")
    public ApiResult selectBy(@RequestBody TProduct param) {
        return ApiResult.ok(tProductService.selectBy(param));
    }

    @ApiOperation("根据ID获取产品详情")
    @GetMapping("/{id}")
    public ApiResult getById(@PathVariable("id") String id) {
        TProduct product = tProductService.findById(id);
        return ApiResult.ok(product);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/deleteById")
    public ApiResult deleteById(@RequestBody TProduct param) {
        tProductService.deleteById(param);
        return ApiResult.ok();
    }
}
